<?php declare(strict_types=1);


namespace App\Api\V2\Controller\Lite;

use App\Api\Controllers\BaseController;
use App\Services\PengYiPeng\SPILiteService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class SpiRefundController extends BaseController
{


    public function refundAuthCode(Request $request): string
    {
        $data = $request->all();
        $url = $request->fullUrl();
        Log::channel("notify-refund")->info("refundcode日志_data" . date("Y-m-d H:i:s", time()), $data);
        Log::channel("notify-refund")->info("refundcode日志_url" . date("Y-m-d H:i:s", time()) . $url);
        //发起支付代码
        $service = new SPILiteService();
        try {
            $result = $service->refundAuthCodeSPI($data);
            Log::channel("notify-refund")->info("handleSPIsuccess_refundAuthCode" . date("Y-m-d H:i:s", time()), $result);
            return json_encode($result);
        } catch (\Exception $e) {
            Log::channel("notify-refund")->info("Exception_refundAuthCode" . date("Y-m-d H:i:s", time()), [$e->getMessage() . $e->getFile() . $e->getLine()]);
            return $e->getMessage() . $e->getFile() . $e->getLine();
        }
    }

    //退款
    public function refund(Request $request): string
    {
        $data = $request->all();
        $url = $request->fullUrl();
        Log::channel("notify-refund")->info("refundcode日志_data" . date("Y-m-d H:i:s", time()), $data);
        Log::channel("notify-refund")->info("refundcode日志_url" . date("Y-m-d H:i:s", time()) . $url);
        //发起支付代码
        $service = new SPILiteService();

        try {
            $result = $service->refundSPI($data);
            Log::channel("notify-refund")->info("handleSPIsuccess_refund" . date("Y-m-d H:i:s", time()), $result);
            return json_encode($result);
        } catch (\Exception $e) {
            Log::channel("notify-refund")->info("Exception_refund" . date("Y-m-d H:i:s", time()), [$e->getMessage() . $e->getFile() . $e->getLine()]);
            return $e->getMessage() . $e->getFile() . $e->getLine();
        }
    }

    public function refundQuery(Request $request): string
    {
        $data = $request->all();
        $url = $request->fullUrl();
        Log::channel("notify-query")->info("refundQuery日志_data" . date("Y-m-d H:i:s", time()), $data);
        Log::channel("notify-query")->info("refundQuery日志_url" . date("Y-m-d H:i:s", time()) . $url);
        //发起支付代码
        $service = new SPILiteService();

        try {
            $result = $service->refundQuerySPI($data);
            Log::channel("notify-query")->info("handleSPIsuccess_refundQuery" . date("Y-m-d H:i:s", time()), $result);
            return json_encode($result);
        } catch (\Exception $e) {
            Log::channel("notify-query")->info("Exception_refundQuery" . date("Y-m-d H:i:s", time()), [$e->getMessage() . $e->getFile() . $e->getLine()]);
            return $e->getMessage() . $e->getFile() . $e->getLine();
        }
    }

}